import {
    ModalForm,
    ProFormText,
    ProFormTextArea,
  } from "@ant-design/pro-components";
  import { Form, message } from "antd";
  import React from "react";
import { saveApiGroup } from "../../../../../api";
import { useParams } from "react-router-dom";
  
  const SaveApiGroup = ({ refresh,children, payload }:any) => {
    const [form] = Form.useForm();
   const urlParams =  useParams()
    return (
      <ModalForm
        initialValues={{
            type:0,
            parentId:0
        }}
        width={400}
        trigger={<span>{children}</span>}
        form={form}
        onOpenChange={(open) => {
          if (open && payload) {
            
            form.setFieldsValue(payload);
          }
        }}
        onFinish={async (e) => {
            e.projectId = urlParams.projectId
          await saveApiGroup(e)
          message.success('保存成功')
          refresh()
          return true
        }}
      >
        <ProFormText hidden name="type" label="分组ID" />
        <ProFormText hidden name="parentId" label="分组ID" />
        <ProFormText hidden name="id" label="分组ID" />
        <ProFormText name="name" label="分组名称" />
      
      </ModalForm>
    );
  };
  export default SaveApiGroup;
  